package com.example.qxfw.shfx.Controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.zy.Flooded;
import com.example.qxfw.shfx.Service.YmfxService;
import com.example.qxfw.shfx.dto.HamletsAndRoadsInfoDto;
import com.example.qxfw.shfx.entity.ColorAndPos;
import com.example.qxfw.yjqx.dto.DlfxDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.io.UnsupportedEncodingException;
import java.util.List;

@ApiIgnore
@Api(tags = "山洪防汛--淹没分析")
@CrossOrigin
@RestController
@RequestMapping("/InundationAnalysisController")
public class InundationAnalysisController {
    @Autowired
    private YmfxService ymfxService;

    @ApiOperation("山洪防汛--淹没分析-自动分析")
    @GetMapping("/automatedAnalysis")
    public SysResult automatedAnalysis(){
        List<ColorAndPos> colorAndPosList = ymfxService.automatedAnalysis();
        return SysResult.success(colorAndPosList);
    }

    @ApiOperation("山洪防汛--淹没分析-淹没分析区")
    @GetMapping("/manualAnalysis")
    public SysResult manualAnalysis(String stationName, double value){
        ColorAndPos colorAndPos = ymfxService.manualAnalysis(stationName, value);
        return SysResult.success(colorAndPos);
    }

    @ApiOperation("山洪防汛--淹没分析-水位站")
    @GetMapping("/getWaterLevelStation")
    public SysResult getWaterLevelStation(){
        List<Flooded> stationName = ymfxService.getWaterLevelStation();
        return SysResult.success(stationName);
    }

    @ApiOperation("山洪防汛--淹没分析-流域区划")
    @GetMapping("/getZoning")
    public SysResult getZoning(String stationName){
        Double[][] pos = ymfxService.getZoning(stationName);
        return SysResult.success(pos);
    }

    @ApiOperation("山洪防汛--淹没分析-水位海拔值判断")
    @GetMapping("/getWaterLevel")
    public SysResult waterLevelJudgment(String stationName){
        List<Flooded> flooded = ymfxService.waterLevelJudgment(stationName);
        return SysResult.success(flooded);
    }

    @ApiOperation("山洪防汛--淹没分析-水位值描述")
    @GetMapping("/descriptionWaterLevel")
    public SysResult descriptionWaterLevel(String stationName, double value){
        String description  = ymfxService.descriptionWaterLevel(stationName, value);
        return SysResult.success(description);
    }

    @ApiOperation("山洪防汛--淹没分析-地理分析")
    @PostMapping("geographicAnalysis")
    public SysResult geographicAnalysis(@RequestBody DlfxDto dlfxDto) throws UnsupportedEncodingException {
        List<HamletsAndRoadsInfoDto> posList = ymfxService.geographicAnalysis(dlfxDto);
        if (posList != null){
            return SysResult.success(posList);
        }else {
            return SysResult.fail("未得到村庄信息");
        }
    }
}
